﻿using Core;
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.SceneManagement;

[CreateAssetMenu(menuName = "Mini/Sys/Conf/Scene")]
public class TblScene : AbstractSOTable<int, TblScene.Conf>, IEnumTable
{
    [Serializable]
    public class Conf : ITableConf<int>
    {
        public int Index => Id;

        [HorizontalGroup("row0")]
        public int Id;

        [HorizontalGroup("row0")]
        public string Name;

        [HorizontalGroup("row0")]
        public LoadSceneMode LoadSceneMode;

        public string PrefabsPath;
        public string LightingPath;

        private string mSceneName = string.Empty;

        public string SceneName
        {
            get
            {
                if (mSceneName != string.Empty)
                {
                    return mSceneName;
                }

                if (LightingPath == string.Empty)
                {
                    return string.Empty;
                }

                mSceneName = new Core.PathParser(LightingPath).Name;
                return mSceneName;
            }
        }

        public void Awake() { }
    }

    public void Print()
    {
        foreach (var item in Confs)
        {
            Debug.Log($"Scene.Conf id={item.Id} name={item.Name}");
        }
    }

    public List<(int, string)> GetEnumList()
    {
        var list = new List<(int, string)>();
        foreach (var conf in Confs)
        {
            list.Add((conf.Id, conf.Name));
        }

        return list;
    }
}